﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
	[TestClass]
	public class UserData_50_DateAndTime_Test
	{
		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test01_Equals_DateTime_IncludingSecond()
		{
			DateTime dtNow = DateTime.Now;
			UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, true);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_40_Test userData2Compare = new UserData_40_Test();
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(userData.DateAndTime, userData.IncludingSecond);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - equal - via alternative constructor
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
					(byte) (userData.DateAndTime.Year / 100), 
					(byte) (userData.DateAndTime.Year % 100),
					(byte) (userData.DateAndTime.Month),
					(byte) (userData.DateAndTime.Day),
					(byte) (userData.DateAndTime.Hour),
					(byte) (userData.DateAndTime.Minute),
					(byte) (userData.DateAndTime.Second)
					);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - not equal - via alternative constructor but no second
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
					(byte)(userData.DateAndTime.Year / 100),
					(byte)(userData.DateAndTime.Year % 100),
					(byte)(userData.DateAndTime.Month),
					(byte)(userData.DateAndTime.Day),
					(byte)(userData.DateAndTime.Hour),
					(byte)(userData.DateAndTime.Minute)
					);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different year (century)
				DateTime diffDateTime = userData.DateAndTime.AddYears(100);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different year (year)
				DateTime diffDateTime = userData.DateAndTime.AddYears(1);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different month
				DateTime diffDateTime = userData.DateAndTime.AddMonths(1);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different day
				DateTime diffDateTime = userData.DateAndTime.AddDays(5);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different hour
				DateTime diffDateTime = userData.DateAndTime.AddHours(23);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different minute
				DateTime diffDateTime = userData.DateAndTime.AddMinutes(54);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different second
				DateTime diffDateTime = userData.DateAndTime.AddSeconds(3);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test02_Equals_DateTime_NoSecond()
		{
			DateTime dtNow = DateTime.Now;
			UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, false);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_40_Test userData2Compare = new UserData_40_Test();
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(userData.DateAndTime, userData.IncludingSecond);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - equal - via alternative constructor
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
					(byte)(userData.DateAndTime.Year / 100),
					(byte)(userData.DateAndTime.Year % 100),
					(byte)(userData.DateAndTime.Month),
					(byte)(userData.DateAndTime.Day),
					(byte)(userData.DateAndTime.Hour),
					(byte)(userData.DateAndTime.Minute)
					);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - not equal - via alternative constructor but no second
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
					(byte)(userData.DateAndTime.Year / 100),
					(byte)(userData.DateAndTime.Year % 100),
					(byte)(userData.DateAndTime.Month),
					(byte)(userData.DateAndTime.Day),
					(byte)(userData.DateAndTime.Hour),
					(byte)(userData.DateAndTime.Minute),
					(byte)(userData.DateAndTime.Second)
					);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different year (century)
				DateTime diffDateTime = userData.DateAndTime.AddYears(100);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different year (year)
				DateTime diffDateTime = userData.DateAndTime.AddYears(1);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different month
				DateTime diffDateTime = userData.DateAndTime.AddMonths(1);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different day
				DateTime diffDateTime = userData.DateAndTime.AddDays(5);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different hour
				DateTime diffDateTime = userData.DateAndTime.AddHours(23);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different minute
				DateTime diffDateTime = userData.DateAndTime.AddMinutes(54);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different second - but this does not matter!
				DateTime diffDateTime = userData.DateAndTime.AddSeconds(3);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(diffDateTime, userData.IncludingSecond);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test03_Equals_Bytes_IncludingSecond()
		{
			UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35, 54);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_40_Test userData2Compare = new UserData_40_Test();
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century, 
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same constructor - but NO seconds
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - alternative constructor, also including seconds
				DateTime dateAndTime = new DateTime(userData.Century * 100 + userData.Year, userData.Month, userData.Day, userData.Hour, userData.Minute, userData.Second);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(dateAndTime, true);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - alternative constructor, NOT including seconds
				DateTime dateAndTime = new DateTime(userData.Century * 100 + userData.Year, userData.Month, userData.Day, userData.Hour, userData.Minute, userData.Second);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(dateAndTime, false);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different century
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						(byte) (userData.Century + 1),
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different year
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						(byte)(userData.Year + 1),
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different month
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year ,
						(byte)(userData.Month + 1),
						userData.Day,
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						(byte)(userData.Day + 1),
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						(byte)(userData.Hour + 1),
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						(byte)(userData.Minute + 1),
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute,
						(byte)(userData.Second + 1));
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test04_Equals_Bytes_NotIncludingSecond()
		{
			UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type 
				UserData_40_Test userData2Compare = new UserData_40_Test();
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same constructor - but seconds
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute,
						userData.Second);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - alternative constructor, also not including seconds
				DateTime dateAndTime = new DateTime(userData.Century * 100 + userData.Year, userData.Month, userData.Day, userData.Hour, userData.Minute, userData.Second);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(dateAndTime, false);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// same object - alternative constructor, but including seconds
				DateTime dateAndTime = new DateTime(userData.Century * 100 + userData.Year, userData.Month, userData.Day, userData.Hour, userData.Minute, userData.Second);
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(dateAndTime, true);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different century
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						(byte)(userData.Century + 1),
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different year
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						(byte)(userData.Year + 1),
						userData.Month,
						userData.Day,
						userData.Hour,
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different month
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						(byte)(userData.Month + 1),
						userData.Day,
						userData.Hour,
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						(byte)(userData.Day + 1),
						userData.Hour,
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						(byte)(userData.Hour + 1),
						userData.Minute);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same constructor - different day
				UserData_50_DateAndTime userData2Compare = new UserData_50_DateAndTime(
						userData.Century,
						userData.Year,
						userData.Month,
						userData.Day,
						userData.Hour,
						(byte)(userData.Minute + 1));
				Assert.IsFalse(userData.Equals(userData2Compare));
			}			
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test05_GetHashCode()
		{
			{
				DateTime dtNow = DateTime.Now;
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, true);
				int hashCode = userData.GetHashCode();
			}

			{
				DateTime dtNow = DateTime.Now;
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, false);
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35, 54);
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35);
				int hashCode = userData.GetHashCode();
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test06_ToString()
		{
			{
				DateTime dtNow = DateTime.Now;
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, true);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				DateTime dtNow = DateTime.Now;
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(dtNow, false);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35, 54);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_50_DateAndTime userData = new UserData_50_DateAndTime(20, 13, 03, 23, 07, 35);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}
		}
	}
}
